package com.ruoyi.web.controller.knowledge;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.law_model.knowledge.domain.DocumentSplit;
import com.ruoyi.law_model.knowledge.service.IDocumentSplitService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 存储文档分段信息Controller
 *
 * @author lihuayong
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/docSplit/split")
public class DocumentSplitController extends BaseController
{
    @Autowired
    private IDocumentSplitService documentSplitService;

    /**
     * 查询存储文档分段信息列表
     */
    @PreAuthorize("@ss.hasPermi('docSplit:split:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocumentSplit documentSplit)
    {
        startPage();
        List<DocumentSplit> list = documentSplitService.selectDocumentSplitList(documentSplit);
        return getDataTable(list);
    }

    /**
     * 导出存储文档分段信息列表
     */
    @PreAuthorize("@ss.hasPermi('docSplit:split:export')")
    @Log(title = "存储文档分段信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocumentSplit documentSplit)
    {
        List<DocumentSplit> list = documentSplitService.selectDocumentSplitList(documentSplit);
        ExcelUtil<DocumentSplit> util = new ExcelUtil<DocumentSplit>(DocumentSplit.class);
        util.exportExcel(response, list, "存储文档分段信息数据");
    }

    /**
     * 获取存储文档分段信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('docSplit:split:query')")
    @GetMapping(value = "/{docSegId}")
    public AjaxResult getInfo(@PathVariable("docSegId") Long docSegId)
    {
        return success(documentSplitService.selectDocumentSplitByDocSegId(docSegId));
    }

    /**
     * 新增存储文档分段信息
     */
    @PreAuthorize("@ss.hasPermi('docSplit:split:add')")
    @Log(title = "存储文档分段信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentSplit documentSplit)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        documentSplit.setCreatedAt(new Date());
        documentSplit.setCreatedBy(String.valueOf(loginUser.getUserId()));
        documentSplit.setUpdatedBy(String.valueOf(loginUser.getUserId()));
        documentSplit.setUpdatedAt(new Date());
        return toAjax(documentSplitService.insertDocumentSplit(documentSplit));
    }

    /**
     * 修改存储文档分段信息
     */
    @PreAuthorize("@ss.hasPermi('docSplit:split:edit')")
    @Log(title = "存储文档分段信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentSplit documentSplit)
    {
        return toAjax(documentSplitService.updateDocumentSplit(documentSplit));
    }

    /**
     * 删除存储文档分段信息
     */
    @PreAuthorize("@ss.hasPermi('docSplit:split:remove')")
    @Log(title = "存储文档分段信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{docSegIds}")
    public AjaxResult remove(@PathVariable Long[] docSegIds)
    {
        return toAjax(documentSplitService.deleteDocumentSplitByDocSegIds(docSegIds));
    }
}
